#delimit;
clear;
use "${datapath}\village_d.dta",replace;

* regression using village data;

eststo:qui ivregress 2sls water22015 (res_w=random) gp1-gp50 sc_pc total_hh1  town_dist irr,robust; 
qui estadd ysumm;
rename draleng dranum;
foreach x in stlit road dra {;
eststo:qui ivregress 2sls `x'num (res_w=random) gp1-gp50 sc_pc total_hh1  town_dist irr,robust;
qui estadd ysumm;
};
esttab, b(3) t(2) keep(res_w) se  compress mtitles("water" "Lights" "Road"  "Drainage") stats(ymean N, labels  ("Mean" "Observations") fmt(2 0)) star(+ 0.10 * 0.05 ** 0.01);
esttab using "${outpath}\v_num.csv", replace label b(3) t(2) keep(res_w) se  compress mtitles("water""Lights" "Road"  "Drainage") stats(ymean N, labels ("Mean" "Observations") fmt(2 0)) star(+ 0.10 * 0.05 ** 0.01)  fragment;
eststo clear;



/* balance */;
 
sum sc_pc total_hh1 town_dist irr if res_w==1;
sum sc_pc total_hh1 town_dist irr if res_w==0;
sum sc_pc total_hh1 town_dist irr if res_w==1&random==1;
foreach x in sc_pc total_hh1 town_dist irr  {;
eststo:qui  reg `x' res_w gp1-gp50 if res_w==random,robust ;
qui estadd ysumm;
};
esttab, b(3) t(2) keep(res_w ) se  compress mtitles("sc_pc" "total" "town_dist" "irr") stats(ymean N, labels  ("Mean" "Observations") fmt(2 0)) star(+ 0.10 * 0.05 ** 0.01) ;
esttab using "${outpath}\v_balance.csv", replace label b(3) t(2) keep(res_w) se  compress mtitles("sc_pc" "total" "town_dist" "irr") stats(ymean N, labels ("Mean" "Observations") fmt(2 0)) star(+ 0.10 * 0.05 ** 0.01)  fragment;
eststo clear;

save "${datapath}\village.dta",replace;


